<template>
  <div class="app-container">
    <transition name="el-zoom-in-top">
      <el-form
        :inline="true"
        size="small"
        v-show="showSearch"
        @keyup.enter.native="getDataList()"
      >
        <el-form-item label="患者姓名">
          <el-input
            style="width: 230px"
            v-model="queryParams.name"
            placeholder="请输入患者姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="患者手机号">
          <el-input
            style="width: 230px"
            v-model="queryParams.phone"
            placeholder="请输入患者手机号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="患者来源">
          <el-cascader
            style="width: 230px"
            :props="defaultProps"
            @change="handleSubChange"
            clearable
            :options="deptOptions"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="患者类型">
          <el-select
            clearable
            v-model="queryParams.patientType"
            placeholder="请选择患者类型"
          >
            <el-option
              style="width: 230px"
              v-for="item in dict.type.chat_patient_type"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="getDataList"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </transition>
    <el-row :gutter="10" class="mb8">
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getDataList"
      ></right-toolbar>
    </el-row>
    <el-table :data="dataList" style="width: 100%" v-loading="loading">
      <el-table-column
        prop="id"
        label="患者编号"
        align="center"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column prop="name" label="患者姓名" align="center"></el-table-column>
      <el-table-column prop="phone" label="患者手机号" align="center"></el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间"
        align="center"
      ></el-table-column>
      <el-table-column label="未读消息" align="center">
        <template slot-scope="scope">
          <span v-if="scope.row.params.noneVisitCount >= 1">
            <el-badge
              style="margin-top: 5px"
              :value="scope.row.params.noneVisitCount"
              class="item"
            ></el-badge
            >条未读消息
          </span>
          <span v-else>暂无</span>
        </template>
      </el-table-column>
      <el-table-column fixed="right" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button
            type="primary"
            size="mini"
            plain
            v-hasPermi="['gonitis:chat:interflow']"
            @click="toInterflow(scope.row.id)"
          >
            在线咨询
            <i class="el-icon-arrow-right"></i>
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getDataList"
    />
  </div>
</template>

<script>
import { subTree } from "@/api/gonitis/illSub";
import { chatList } from "@/api/gonitis/chat";
export default {
  name: "Chat",
  dicts: ["chat_patient_type"],
  data() {
    return {
      // 展示搜索栏
      showSearch: true,
      // 病情多选框映射
      defaultProps: {
        children: "children",
        label: "label",
        value: "id",
      },
      // 病情列表
      deptOptions: [],
      loading: false,
      total: 0,
      queryParams: {
        pageSize: 10,
        pageNum: 1,
        subId: undefined,
        name: undefined,
        phone: undefined,
        patientType: undefined,
      },
      dataList: [],
    };
  },
  //方法集合
  methods: {
    /** 初始化 */
    init() {
      this.getDataList();
      this.getDeptTree();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getDataList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.name = undefined;
      this.queryParams.phone = undefined;
      this.queryParams.subId = undefined;
      this.queryParams.patientType = undefined;
      this.handleQuery();
    },
    /** 病情分类选择框改变 */
    handleSubChange(value) {
      if (value.length === 3) {
        this.queryParams.subId = value[2];
      } else {
        this.queryParams.subId = undefined;
      }
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      subTree().then((response) => {
        this.deptOptions = response.data;
      });
    },
    /** 跳转至聊天界面 */

    toInterflow(id) {
      // 带着basicId跳转到form页面
      this.$router.push({
        name: "InterFlow",
        params: { id: id },
      });
    },
    /** 获取聊天病人集合 */
    getDataList() {
      this.loading = true;
      chatList(this.queryParams).then((response) => {
        this.dataList = response.data.list;
        this.total = response.data.totalCount;
        this.loading = false;
      });
    },
  },
  created() {
    this.init();
  },
};
</script>
<style scoped></style>
.
